package com.jt.msg.req;

import com.jt.msg.DataPacket;
import com.jt.utils.BCD;
import io.netty.buffer.ByteBuf;

/**
 * 位置包
 *
 * @author wang xiao
 * date 2023/8/9
 */
public class LocationMsg extends DataPacket {

    /**
     * 告警信息 4字节
     */
    private int alarm;
    /**
     * 状态 4字节
     */
    private int statusField;
    /**
     * 纬度 4字节
     */
    private float latitude;
    /**
     * 经度 4字节
     */
    private float longitude;
    /**
     * 海拔高度 2字节
     */
    private short elevation;
    /**
     * 速度 2字节
     */
    private short speed;
    /**
     * 方向 2字节
     */
    private short direction;
    /**
     * 时间 6字节BCD
     */
    private String time;

    /**
     * 里程数
     */
    private long mileage;



    public LocationMsg(ByteBuf byteBuf) {
        super(byteBuf);
    }

    @Override
    public void parseBody() {
        ByteBuf bb = this.payload;
        this.setAlarm(bb.readInt());
        this.setStatusField(bb.readInt());
        this.setLatitude(bb.readUnsignedInt() * 1.0F / 1000000);
        this.setLongitude(bb.readUnsignedInt() * 1.0F / 1000000);
        this.setElevation(bb.readShort());
        this.setSpeed(bb.readShort());
        this.setDirection(bb.readShort());
        this.setTime(BCD.toBcdTimeString(readBytes(6)));
        // 跳过2 字节 直接读取 里程数，如果数据顺序发生改变，那再说
        bb.skipBytes(2);
        this.setMileage(bb.readUnsignedInt());
    }

    public int getAlarm() {
        return alarm;
    }

    public void setAlarm(int alarm) {
        this.alarm = alarm;
    }

    public int getStatusField() {
        return statusField;
    }

    public void setStatusField(int statusField) {
        this.statusField = statusField;
    }

    public float getLatitude() {
        return latitude;
    }

    public void setLatitude(float latitude) {
        this.latitude = latitude;
    }

    public float getLongitude() {
        return longitude;
    }

    public void setLongitude(float longitude) {
        this.longitude = longitude;
    }

    public short getElevation() {
        return elevation;
    }

    public void setElevation(short elevation) {
        this.elevation = elevation;
    }

    public short getSpeed() {
        return speed;
    }

    public void setSpeed(short speed) {
        this.speed = speed;
    }

    public short getDirection() {
        return direction;
    }

    public void setDirection(short direction) {
        this.direction = direction;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public long getMileage() {
        return mileage;
    }

    public void setMileage(long mileage) {
        this.mileage = mileage;
    }

    @Override
    public String toString() {
        return "LocationMsg{" +
                "alarm=" + alarm +
                ", statusField=" + statusField +
                ", latitude=" + latitude +
                ", longitude=" + longitude +
                ", elevation=" + elevation +
                ", speed=" + speed +
                ", direction=" + direction +
                ", time='" + time + '\'' +
                ", mileage=" + mileage +
                '}';
    }
}
